package com.jsong.linuo.controlstructure;

import java.util.Random;
import java.util.Scanner;

/*
    猜数字小游戏
    1.创建Scanner和Random对象
    2.调用Random中nextIn(100)+1在1~100中随机生成一个数 rsNumber
    3.调用Scanner中nextIn()方法,在键盘中输入一个数 scNumber
    4.比较rsNumber和scNumber 猜大了/猜小了/猜对了
 */
public class Exercise {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        Random rd = new Random();

        int rdNumber = rd.nextInt(100) + 1;

        while (true) {
            System.out.println("请您猜一个数:");
            int scNumber = sc.nextInt();

            if (scNumber > rdNumber) {
                System.out.println("对不起,您猜大了");
            } else if (scNumber < rdNumber) {
                System.out.println("对不起,您猜小了");
            } else {
                System.out.println("恭喜您猜对了");
                break;
            }
        }

    }
}
